package cn.itsource.org.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private IShopService shopService;

    @PostMapping("/settlement")
    public AjaxResult settledIn(@RequestBody Shop shop){
        try {
            shopService.saveSetIn(shop);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }

    }

    /**
     * 查询状态为待审核的商家
     * @return
     */
    @GetMapping("/getShopByState")
    public List<Shop> getShopByState(){
        return  shopService.getShopByState();
    }

    /**
     * 根据id更新状态码
     * @return
     */
    @PutMapping("/updateState/{id}")
    public AjaxResult updateState(@PathVariable("id") Long id){
        try {
            shopService.updateState(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"更新失败");
        }
    }



}
